$(document).ready(function (e) {
	//controller list
	$controllers = $('.language-controller-list ul li');
	$first = $controllers.eq(0);
	
	//call first element
	$first.click();
});

//live click lang element
$('.language-controller-list ul li').live('click', function (e) {
	$('.language-controller-list ul li').removeClass('selected');
	$(this).addClass('selected');

	if ($(this).attr('url')) {
		$e = $(this);
		//call form
		$.ajax({
			url: $e.attr('url'),
			beforeSend: function () {
				wait_block('language-content', JAVASCRIPT_WAIT);
			},
			success: function(msg) {
				$('#language-content form').html(msg).animate({scrollTop: 0}, 'slow');;
			},
			complete: function () {
				//call administrator button
				bAdmin = '<a href="javascript:void(0)" class="bAdmin" onclick="$(\'#edit-language\').submit();">'+ JAVASCRIPT_SAVE_LANG +' '+ $e.html() +'</a>';
				bAdmin += '<a href="javascript:void(0)" class="bAdmin add-element">'+ JAVASCRIPT_ADD_KEY_TO +' '+ $e.html() +'</a>';
				$('.language-controller-list a.bAdmin').remove();
				$('.language-controller-list').append(bAdmin);
			}
		});
	}
	
});

//add generic element
$('a.add-element').live('click', function(e) {
	
	//create content
	_genelement = '<label>'+ JAVASCRIPT_KEY_NAME +' - <input type="text" class="extrakey required" name="new[key][]"/> - <span class="remove-key"><img src="'+baseurl+'/img-pack/application/buttons/remove-extra.png" width="15"/></span></label>';
	_genelement += '<span><input type="text" class="extravalue textfield required" name="new[value][]"/></span>';
	
	//insert element
	$('#language-content form').append(_genelement);
	$('span.remove-key').css('cursor', 'pointer');
	
	return false;
});

//remove generic key
$('span.remove-key').live('click', function(e) {
	
	$(this).parent().next().fadeOut(500, function () {
		$(this).remove();
	});
	
	$(this).parent().fadeOut(500, function () {
		$(this).remove();
	});
});

var process = function(data, target) {
	$('#documentresponse').html(data.message);
};